package com.esri.core.geometry;

/* loaded from: classes.dex */
class IndexMultiList {
    AttributeStreamOfInt32 a;
    AttributeStreamOfInt32 b;
    int c;
    int d;
    int e;
    int f;
    int g;

    public static int nullNode() {
        return -1;
    }

    void a(int i) {
        this.a.set(i, nullNode());
        this.a.set(i + 1, this.e);
        this.e = i;
    }

    int a() {
        if (this.e != nullNode()) {
            int i = this.e;
            this.e = this.a.get(i + 1);
            this.a.set(i + 1, nullNode());
            return i;
        }
        int size = this.a.size();
        this.a.add(nullNode());
        this.a.add(nullNode());
        return size;
    }

    void b(int i) {
        this.b.set(i, nullNode());
        this.b.set(i + 1, this.f);
        this.b.set(i + 2, nullNode());
        this.b.set(i + 3, nullNode());
        this.f = i;
    }

    int b() {
        if (this.f != nullNode()) {
            int i = this.f;
            int i2 = i + 1;
            this.f = this.b.get(i2);
            this.b.set(i2, nullNode());
            return i;
        }
        int size = this.b.size();
        this.b.add(nullNode());
        this.b.add(nullNode());
        this.b.add(nullNode());
        this.b.add(nullNode());
        return size;
    }

    public IndexMultiList() {
        AttributeStreamOfInt32 attributeStreamOfInt32 = new AttributeStreamOfInt32(0);
        this.a = attributeStreamOfInt32;
        attributeStreamOfInt32.reserve(256);
        AttributeStreamOfInt32 attributeStreamOfInt322 = new AttributeStreamOfInt32(0);
        this.b = attributeStreamOfInt322;
        attributeStreamOfInt322.reserve(256);
        this.e = nullNode();
        this.f = nullNode();
        this.c = 0;
        this.d = 0;
        this.g = nullNode();
    }

    public int createList() {
        int b = b();
        this.b.write(b + 0, nullNode());
        this.b.write(b + 1, nullNode());
        this.b.write(b + 2, nullNode());
        this.b.write(b + 3, this.g);
        if (this.g != nullNode()) {
            this.b.write(this.g + 2, b);
        }
        this.d++;
        this.g = b;
        return b;
    }

    public void deleteList(int i) {
        int first = getFirst(i);
        while (first != nullNode()) {
            int next = getNext(first);
            a(first);
            this.c--;
            first = next;
        }
        int read = this.b.read(i + 2);
        int read2 = this.b.read(i + 3);
        if (read != nullNode()) {
            this.b.write(read + 3, read2);
        } else {
            this.g = read2;
        }
        if (read2 != nullNode()) {
            this.b.write(read2 + 2, read);
        }
        b(i);
        this.d--;
    }

    public int addElement(int i, int i2) {
        int i3 = i + 1;
        int read = this.b.read(i3);
        int a = a();
        if (read != nullNode()) {
            this.a.write(read + 1, a);
            this.b.write(i3, a);
        } else {
            this.b.write(i + 0, a);
            this.b.write(i3, a);
        }
        this.a.write(a, i2);
        this.c++;
        return a;
    }

    public void deleteElement(int i, int i2, int i3) {
        if (i2 != nullNode()) {
            AttributeStreamOfInt32 attributeStreamOfInt32 = this.a;
            attributeStreamOfInt32.write(i2 + 1, attributeStreamOfInt32.read(i3 + 1));
            int i4 = i + 1;
            if (this.b.read(i4) == i3) {
                this.b.write(i4, i2);
            }
        } else {
            this.b.write(i, this.a.read(i3 + 1));
            int i5 = i + 1;
            if (this.b.read(i5) == i3) {
                this.b.set(i5, nullNode());
            }
        }
        a(i3);
        this.c--;
    }

    public int concatenateLists(int i, int i2) {
        int i3 = i + 1;
        int i4 = this.b.get(i3);
        int i5 = this.b.get(i2);
        if (i5 != nullNode()) {
            if (i4 != nullNode()) {
                this.a.set(i4 + 1, i5);
                AttributeStreamOfInt32 attributeStreamOfInt32 = this.b;
                attributeStreamOfInt32.set(i3, attributeStreamOfInt32.get(i2 + 1));
            } else {
                this.b.set(i, i5);
                AttributeStreamOfInt32 attributeStreamOfInt322 = this.b;
                attributeStreamOfInt322.set(i3, attributeStreamOfInt322.get(i2 + 1));
            }
        }
        int i6 = this.b.get(i2 + 2);
        int i7 = this.b.get(i2 + 3);
        if (i6 != nullNode()) {
            this.b.set(i6 + 3, i7);
        } else {
            this.g = i7;
        }
        if (i7 != nullNode()) {
            this.b.set(i7 + 2, i6);
        }
        b(i2);
        this.d--;
        return i;
    }

    public int getElement(int i) {
        return this.a.get(i);
    }

    public void setElement(int i, int i2) {
        this.a.set(i, i2);
    }

    public int getNext(int i) {
        return this.a.get(i + 1);
    }

    public int getFirst(int i) {
        return this.b.get(i);
    }

    public int getFirstElement(int i) {
        return getElement(getFirst(i));
    }

    public void clear() {
        AttributeStreamOfInt32 attributeStreamOfInt32 = new AttributeStreamOfInt32(0);
        this.a = attributeStreamOfInt32;
        attributeStreamOfInt32.reserve(256);
        AttributeStreamOfInt32 attributeStreamOfInt322 = new AttributeStreamOfInt32(0);
        this.b = attributeStreamOfInt322;
        attributeStreamOfInt322.reserve(256);
        this.e = nullNode();
        this.f = nullNode();
        this.c = 0;
        this.d = 0;
    }

    public boolean isEmpty(int i) {
        return this.b.get(i) == nullNode();
    }

    public boolean IsEmpty() {
        return this.c == 0;
    }

    public int getNodeCount() {
        return this.c;
    }

    public int getListCount() {
        return this.d;
    }

    public int getFirstList() {
        return this.g;
    }

    public int getNextList(int i) {
        return this.b.get(i + 3);
    }
}
